<div class="content-wrapper">
    <?php
    $form = $this->form;
    $form->prepare();
    ?>
    <?php echo $this->form()->openTag($form); ?>
    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>

        <h1 class="pull-right" id="dbshop-menu-top">
            <a href="<?php echo $this->url('goods-class');?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?php echo $this->translate('返回分类列表'); ?></a>
            <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> <?php echo $this->translate('保存分类'); ?></button>
            <?php echo $this->HelpUrl('goodsClassAdd'); ?>
        </h1>
    </section>

    <section class="content">

        <div class="row">
            <div class="col-md-12">
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_1" data-toggle="tab"><?php echo $this->translate('基本信息'); ?></a></li>
                        <?php if(isset($this->classInfo)) { ?>
                        <li><a href="#tab_2" data-toggle="tab"><?php echo $this->translate('分类商品'); ?></a></li>
                        <?php } ?>
                        <li><a href="#tab_6" data-toggle="tab"><?php echo $this->translate('SEO优化'); ?></a></li>
                    </ul>
                    <div class="tab-content">
                        <?php echo $this->partial('layout/messages'); ?>
                        <div class="tab-pane active" id="tab_1">
                            <div class="box-body">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('分类名称'); ?><span class="must_add_value">*</span></label>
                                    <div class="col-sm-6">
                                        <?php echo $this->formElement($form->get('className')); ?>
                                        <?php echo $this->formElementErrors($form->get('className'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('上级分类'); ?></label>
                                    <div class="col-sm-3">
                                        <?php echo $this->formElement($form->get('classTopId')); ?>
                                        <?php echo $this->formElementErrors($form->get('classTopId'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <?php if(!isset($this->type) || $this->type != 'addMore') { ?>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('分类图片'); ?></label>
                                    <div class="col-sm-3">
                                        <?php if(is_string($form->get('classImage')->getValue())) { ?>
                                            <img src="<?php echo $this->basePath($form->get('classImage')->getValue()); ?>" style="max-width: 300px;padding-bottom: 5px;">
                                        <?php } ?>

                                        <?php echo $this->formElement($form->get('classImage')); ?>
                                        <?php echo $this->formElementErrors($form->get('classImage'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <?php } ?>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('排序'); ?></label>
                                    <div class="col-sm-2">
                                        <?php echo $this->formElement($form->get('classSort')); ?>
                                        <?php echo $this->formElementErrors($form->get('classSort'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('状态'); ?></label>
                                    <div class="col-sm-4">
                                        <div class="checkbox">
                                            <label>
                                                <?php echo $this->formElement($form->get('classState')); ?><?php echo $this->translate('启用'); ?>
                                                <?php echo $this->formElementErrors($form->get('classState'), ['class'=>'error-message']); ?>
                                            </label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('标签组显示'); ?></label>
                                    <div class="col-sm-10">
                                        <?php echo $this->formElement($form->get('classTagGroup')); ?>
                                        <?php echo $this->formElementErrors($form->get('classTagGroup'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <?php if(isset($this->classInfo)) { ?>
                        <div class="tab-pane" id="tab_2">
                            <div class="box-body table-responsive no-padding" id="goodsListBody">
                                <table class="table shop-table">
                                    <thead>
                                    <tr class="shop-bg-thead">
                                        <th width="5%">ID</th>
                                        <th width="45%"><?php echo $this->translate('商品名称'); ?></th>
                                        <th width="15%"><?php echo $this->translate('商品状态'); ?></th>
                                        <th width="10%"><?php echo $this->translate('排序'); ?></th>
                                        <th width="10%"><?php echo $this->translate('分类推荐'); ?></th>
                                        <th width="15%"><?php echo $this->translate('操作'); ?></th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php if(isset($this->goodsList)) foreach ($this->goodsList as $goodsValue) { ?>
                                        <tr id="in-goods-<?php echo $goodsValue[0]->getInId(); ?>">
                                            <td><?php echo $goodsValue[0]->getGoodsId(); ?></td>
                                            <td><?php echo $this->escapeHtml($goodsValue['goodsName']); ?></td>
                                            <td><?php echo $this->goodsHelper()->goodsState($goodsValue['goodsState']); ?></td>
                                            <td><input type="number" min="1" name="classGoodsSort_<?php echo $goodsValue[0]->getInId(); ?>" id="classGoodsSort_<?php echo $goodsValue[0]->getInId(); ?>" value="<?php echo $goodsValue[0]->getClassGoodsSort(); ?>" class="form-control input-sm"></td>
                                            <td>
                                                <select name="classGoodsRecommend_<?php echo $goodsValue[0]->getInId(); ?>" id="classGoodsRecommend_<?php echo $goodsValue[0]->getInId(); ?>" class="form-control input-sm">
                                                    <option value="0" <?php echo $goodsValue[0]->getClassGoodsRecommend() == 0 ? 'selected' : ''; ?>><?php echo $this->translate('否'); ?></option>
                                                    <option value="1" <?php echo $goodsValue[0]->getClassGoodsRecommend() == 1 ? 'selected' : ''; ?>><?php echo $this->translate('是'); ?></option>
                                                </select>
                                                </td>
                                            <td>
                                                <a href="javascript:;" onclick="updateClassGoods(<?php echo $goodsValue[0]->getInId(); ?>);" class="btn btn-xs btn-success"><i class="fa fa-refresh"></i> <?php echo $this->translate('更新'); ?></a>
                                                <?php if($this->classInfo->getClassId() != $goodsValue['classId']) { ?>
                                                    <a href="javascript:;" onclick="deleteNotConfirm( '<?php echo $this->url('goods-class', ['action'=>'deleteClassGoods', 'id'=>$goodsValue[0]->getInId()]); ?>', 'in-goods-<?php echo $goodsValue[0]->getInId(); ?>');" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i> <?php echo $this->translate('删除'); ?></a>
                                                <?php } ?>
                                            </td>
                                        </tr>
                                    <?php } ?>
                                    </tbody>
                                    <tfoot>
                                    <tr>
                                        <td colspan="6">
                                            <?php echo $this->paginationControl($this->goodsList,
                                                'Sliding',
                                                'layout/ajaxPage',
                                                ['route' => 'goods-class', 'params' => ['action' => 'ajaxClassGoods', 'id' => $this->classInfo->getClassId()], 'showDivId' => 'goodsListBody']); ?>
                                        </td>
                                    </tr>
                                    </tfoot>
                                </table>
                            </div>
                        </div>
                        <?php } ?>
                        <div class="tab-pane" id="tab_6">
                            <div class="box-body">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('扩展名称'); ?></label>
                                    <div class="col-sm-8">
                                        <?php echo $this->formElement($form->get('classExtend')); ?>
                                        <?php echo $this->formElementErrors($form->get('classExtend'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('分类关键字'); ?></label>
                                    <div class="col-sm-8">
                                        <?php echo $this->formElement($form->get('classKeywords')); ?>
                                        <?php echo $this->formElementErrors($form->get('classKeywords'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('分类描述'); ?></label>
                                    <div class="col-sm-8">
                                        <?php echo $this->formElement($form->get('classDescription')); ?>
                                        <?php echo $this->formElementErrors($form->get('classDescription'), ['class'=>'error-message']); ?>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>

    </section>
    <?php echo $this->form()->closeTag(); ?>
</div>
<script>
    $(document).ready(function() {
        $("#<?php echo $form->getName(); ?>").validate({
            rules: {
                className: {
                    required: true
                },
                classSort: {
                    required: true,
                    number: true,
                    min: 1
                }
            },
            messages: {
                className: {
                    required: "<?php echo $this->translate('分类名称不能为空!'); ?>"
                },
                classSort: {
                    required: "<?php echo $this->translate('排序不能为空!'); ?>",
                    number: "<?php echo $this->translate('排序必须为数字!'); ?>",
                    min: "<?php echo $this->translate('排序最小为1!'); ?>"
                }
            }
        });
    });

    function updateClassGoods(inId) {
        $.post('<?php echo $this->url('goods-class', ['action'=>'updateClassGoods']); ?>', {inId:inId, classGoodsSort:$('#classGoodsSort_'+inId).val(), classGoodsRecommend:$('#classGoodsRecommend_'+inId).val()}, function (data) {
            shopMessage(data.msg);
        }, 'json');
    }
</script>
